﻿package payments;
import java.awt.*;
import java.awt.event.*;

public class YesNoDialog extends Dialog implements ActionListener {

	private static final long serialVersionUID = 1L;
	
	private Button ok = new Button("ok");
	
	private Button yes = new Button("Да");
	private Button no = new Button("Нет");
	
	private boolean result;

  public YesNoDialog(Frame parent, String message)
  {
    super(parent, true);
    
    Panel p = new Panel();
    GridBagLayout gbl = new GridBagLayout();
    p.setLayout(gbl);
   
    GridBagConstraints c = new GridBagConstraints();
    
    c.anchor = GridBagConstraints.NORTH;//.NORTHWEST; 
    c.fill   = GridBagConstraints.HORIZONTAL;
    
    c.ipadx = 1;
    c.ipady = 1;
    c.insets = new Insets(5, 5, 5, 5);
    
    c.weighty = 1.0;
    c.weightx = 1.0;
    
    c.gridwidth  = GridBagConstraints.REMAINDER;	//последняя ячейка в строке
    c.gridheight = 4;
    c.gridx = GridBagConstraints.RELATIVE;
    c.gridy = GridBagConstraints.RELATIVE;
        
    Label messglabel=new Label(message);
    gbl.setConstraints(messglabel, c);
    p.add(messglabel);
 
    c.ipadx = 100;
    c.gridwidth = GridBagConstraints.RELATIVE;		//Следующая ячейка в строке
    c.gridheight = GridBagConstraints.REMAINDER;	//последняя ячейка в колонке
    
    gbl.setConstraints(yes, c);
    yes.addActionListener(this);
    p.add(yes);
    
    c.gridwidth  = GridBagConstraints.REMAINDER; 	//последняя ячейка в строке

    gbl.setConstraints(no, c);
    no.addActionListener(this);
    p.add(no);
   
    this.add(p);
    //this.setSize(300,100);
    //this.setLocation(50, 50);
    this.pack();
  }  
  
  
  public YesNoDialog(Frame parent, String message, Color col)
  {
	  super(parent, true);
	    
	    Panel p = new Panel();
	    GridBagLayout gbl = new GridBagLayout();
	    p.setLayout(gbl);
	   
	    p.setBackground(col);
	    
	    GridBagConstraints c = new GridBagConstraints();
	    
	    c.anchor = GridBagConstraints.NORTH;//.NORTHWEST; 
	    c.fill   = GridBagConstraints.HORIZONTAL;
	    
	    c.ipadx = 1;
	    c.ipady = 1;
	    c.insets = new Insets(5, 5, 5, 5);
	    
	    c.weighty = 1.0;
	    c.weightx = 1.0;
	    
	    c.gridwidth  = GridBagConstraints.REMAINDER;	//последняя ячейка в строке
	    c.gridheight = 4;
	    c.gridx = GridBagConstraints.RELATIVE;
	    c.gridy = GridBagConstraints.RELATIVE;
	        
	    Label messglabel=new Label(message);
	    gbl.setConstraints(messglabel, c);
	    p.add(messglabel);
	 
	    c.gridwidth  = GridBagConstraints.REMAINDER; 	//последняя ячейка в строке
	    c.ipadx = 100;
	    c.gridwidth = GridBagConstraints.RELATIVE;		//Следующая ячейка в строке
	    c.gridheight = GridBagConstraints.REMAINDER;	//последняя ячейка в колонке
	    
	    gbl.setConstraints(ok, c);
	    ok.addActionListener(this);
	    p.add(ok);
	    
	    this.add(p);
	    //this.setSize(300,100);
	    //this.setLocation(50, 50);
	    this.pack();
  }  
  
    
  public void actionPerformed(ActionEvent evt) {
	
	  if (evt.getSource() == yes) result = true;
	    else result = false;
	  
	  this.setVisible(false);
	  this.dispose();
  }
  
  public boolean getResult() {
	    return result;
	  }
}